<template>
	<view class="">
		<button open-type="launchApp" app-parameter="wechat" binderror='launchAppError'>返回app</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				order_id: '',
				type: ''
			}
		},
		onLoad(e) {
			////console.log('e', e)
			this.order_id = e.query
			this.type = e.type
			this.getcode()
		},
		methods: {
			getcode() {
				uni.login({
					provider: 'weixin',
					success: (res) => {
						////console.log('res', res)
						this.code = res.code
						this.getInfo()
					}
				})
			},
			getInfo() {
				var data = {
					order_id: this.order_id,
					js_code: this.code,
					type: this.type
				}
				uni.showLoading({
					title: '正在加载中....'
				})
				this.$Request.post(this.$api.user.miniWechatPay, data).then(res => {
					////console.log('res111111', res)
					uni.hideLoading()
					this.payurl = res.data.pay_data
					this.order_id = res.data.order_id
					this.Payment(res.data.pay_data)
				})
			},
			Payment(pay_data) {
				let provider = ''
				provider = 'wxpay'

				//调用支付
				let that = this
				uni.requestPayment({
					provider: provider,
					timeStamp: pay_data.timeStamp,
					nonceStr: pay_data.nonceStr,
					signType: 'MD5',
					package: pay_data.package,
					paySign: pay_data.paySign,
					success() {
						uni.showToast({
							title: '支付成功',
							icon: 'none'
						})
					},
					fail(res) {
						uni.showToast({
							title: '支付失败',
							icon: 'none'
						})
					}
				})
			},

		}
	}
</script>

<style>
</style>
